package vuelta.general.util.web;

import vuelta.general.BaseActivity;
import vuelta.general.R;
import android.app.ProgressDialog;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.Toast;

public class WebViewGiroMobile extends BaseActivity {

	private WebView mWebView;
	private ProgressDialog progressBar;

	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.webview);
		initToolbar();

		mWebView = (WebView) findViewById(R.id.webview);
		mWebView.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY);

		mWebView.getSettings().setLoadWithOverviewMode(true);
		mWebView.getSettings().setUseWideViewPort(true);
		mWebView.getSettings().setJavaScriptEnabled(true);
		mWebView.getSettings().setDomStorageEnabled(true);
	//	mWebView.getSettings().setSupportZoom(true); // Zoom Control on web (You
														// don't need this
		// if ROM supports Multi-Touch
	//	mWebView.getSettings().setBuiltInZoomControls(true); // Enable
																// Multitouch if
																// supported by
																// ROM
		
//		String url = getIntent().getStringExtra("url");

		// final AlertDialog alertDialog = new
		// AlertDialog.Builder(this).create();

		progressBar = ProgressDialog.show(WebViewGiroMobile.this, "Wait",
				"Loading...");
		progressBar.setCancelable(true);
		mWebView.setWebViewClient(new WebViewClient() {
			public void onReceivedError(WebView view, int errorCode,
					String description, String failingUrl) {
				Toast.makeText(WebViewGiroMobile.this, description,
						Toast.LENGTH_SHORT).show();
			}

			public boolean shouldOverrideUrlLoading(WebView view, String url) {
//				Log.i("Error webView", "Processing webview url click...");
				String youtubeUrl = "http://www.youtube.com/watch?v=cxLG2wtE7TM"
				    ;
				  startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(youtubeUrl)));
				
				return true;
			}

			public void onPageFinished(WebView view, String url) {
//				Log.i("Error webView", "Finished loading URL: " + url);
				if (progressBar.isShowing()) {
					progressBar.dismiss();
				}
			}
			
		});

	//	 WebSettings webSettings = mWebView.getSettings(); 
	//	 webSettings.setJavaScriptEnabled(true); 
	//	 <iframe width="560" height="315" src="http://www.youtube.com/embed/-GucXHx5LOI" frameborder="0" allowfullscreen></iframe>
		 String playVideo= "<html><body>Youtube video .. <br> <iframe class=\"youtube-player\" type=\"text/html\" width=\"640\" height=\"385\" src=\"http://www.youtube.com/embed/-GucXHx5LOI\" frameborder=\"0\"></body></html>";

		 mWebView.loadData(playVideo, "text/html", "utf-8");
		
	//	mWebView.loadUrl("http://www.youtube.com/watch?v=_1BwnZlO9oY&feature=g-all-u");
	}

}



